
Introduction
PHP (Hypertext Preprocessor) is a popular scripting language used for web development. To develop and test PHP applications locally, we need a local server environment. XAMPP and WAMP are two widely used solutions that provide an easy-to-use local development environment.
In this guide, we will walk you through the process of installing PHP using XAMPP and WAMP, configuring them, and running a simple PHP script.
1. Understanding Local Servers: XAMPP vs. WAMP
A local server environment allows developers to run and test PHP applications on their computer without requiring an internet connection. The two most popular options are:
- XAMPP: A cross-platform software package that includes Apache, MariaDB, PHP, and Perl. Works on Windows, macOS, and Linux.
- WAMP: A Windows-based software stack that includes Apache, MySQL, and PHP. It is designed specifically for Windows users.
Key Differences
2. Installing XAMPP
Step 1: Download XAMPP
- Visit the official XAMPP website.
- Download the latest version for your operating system (Windows, macOS, or Linux).
Step 2: Install XAMPP
- Run the downloaded installer file.
- Follow the installation wizard:
- Select components (default selection is recommended).
- Choose the installation directory (e.g.,
C:\xampp
). - Complete the installation.
- Launch XAMPP Control Panel after installation.
Step 3: Start Apache and MySQL
- Open the XAMPP Control Panel.
- Click Start next to Apache and MySQL.
- If you see green indicators, the services are running.
Step 4: Verify Installation
- Open a browser and type
http://localhost
. - You should see the XAMPP dashboard.
- To check PHP, create a file
test.php
inC:\xampp\htdocs\
with the following content:
<?php phpinfo(); ?>
- Open
http://localhost/test.php
in a browser. If PHP information is displayed, the setup is successful.
3. Installing WAMP
Step 1: Download WAMP
- Visit the official WAMP website.
- Download the appropriate version (32-bit or 64-bit) based on your system.
Step 2: Install WAMP
- Run the downloaded installer.
- Follow the installation wizard:
- Select components (default selection is recommended).
- Choose the installation directory (e.g.,
C:\wamp64
). - Complete the installation.
Step 3: Start WAMP Server
- Launch WAMP from the Start Menu or Desktop shortcut.
- If the WAMP icon in the system tray is green, it means all services (Apache, MySQL, PHP) are running.
- If the icon is orange, some services may not be running. Restart WAMP or check for port conflicts.
Step 4: Verify Installation
- Open a browser and type
http://localhost
. - You should see the WAMP homepage.
- Create a file
test.php
insideC:\wamp64\www\
with the following content:
<?php phpinfo(); ?>
- Open
http://localhost/test.php
in a browser. If PHP information is displayed, the setup is successful.
4. Configuring PHP in XAMPP/WAMP
Changing PHP Version (For Multiple Versions)
- In XAMPP: Switch PHP versions via the control panel.
- In WAMP: Click the WAMP icon > PHP > Version and select the desired version.
Changing PHP Configuration (php.ini)
- Locate
php.ini
:
- XAMPP:
C:\xampp\php\php.ini
- WAMP:
C:\wamp64\bin\php\phpX.X.X\php.ini
- Open
php.ini
in a text editor. - Modify necessary settings, e.g., increase file upload size:
upload_max_filesize = 64M post_max_size = 64M
- Restart Apache after making changes.
5. Running PHP Scripts
- Create a new file
hello.php
in the respectivehtdocs
orwww
folder:
<?php echo "Hello, World!"; ?>
- Open
http://localhost/hello.php
in a browser. - You should see Hello, World! displayed.
6. Common Issues and Troubleshooting
Port Conflict with Apache
- If Apache doesn’t start, another application may be using port 80.
- Change Apache’s port:
- Open
httpd.conf
(located inC:\xampp\apache\conf\
orC:\wamp64\bin\apache\apacheX.X.X\conf\
). - Find
Listen 80
and change it toListen 8080
. - Restart Apache and access
http://localhost:8080
.
MySQL Not Starting
- Ensure MySQL is not running from another service.
- Change the MySQL port from 3306 to 3307 in the my.ini file.
Missing vcruntime140.dll
Error (For WAMP)
- Install the Microsoft Visual C++ Redistributable.
Conclusion
Setting up PHP using XAMPP or WAMP is straightforward and provides a complete local development environment. XAMPP is cross-platform, while WAMP is tailored for Windows users. By following this guide, you can install, configure, and run PHP applications locally with ease.
With your local server set up, you’re ready to start developing dynamic PHP applications efficiently!
Leave a Comment